import request from '@/utils/request.js'
const api_name = '/portal/order'

// 生成订单
export function saveOrder (data) {
  return request({
    url: `${api_name}/`,
    method: 'post',
    data
  })
}

// 生成免费订单
export function saveFreeOrder (data) {
  return request({
    url: `${api_name}/free`,
    method: 'post',
    data
  })
}


// 根据订单号查询订单
export function getOrderById (id) {
  return request({
    url: `${api_name}/${id}`,
    method: 'get'
  })
}

// 订单分页查询
export function getOrderPageList (page,limit,data) {
  return request({
    url: `${api_name}/${page}/${limit}`,
    method: 'get',
    params: data
  })
}

// 删除订单
export function removeOrderById (id) {
  return request({
    url: `${api_name}/${id}`,
    method: 'delete'
  })
}

// 取消订单
export function cancelOrderById (id) {
  return request({
    url: `${api_name}/${id}`,
    method: 'put'
  })
}

// 消费记录分页查询
export function getBillPageList (page,limit,userId) {
  return request({
    url: `${api_name}/bill/${page}/${limit}/${userId}`,
    method: 'get',
  })
}

// 根据课时id判断用户是否已购买课程
export function isBuyCourse (data) {
  return request({
    url: `${api_name}/user`,
    method: 'get',
    params: data
  })
}

// 根据视频id判断用户是否已购买课程
export function isBuyVideo (data) {
  return request({
    url: `${api_name}/user/video`,
    method: 'get',
    params: data
  })
}
